package com.park.controller;

import com.park.bean.Tickets;
import com.park.bean.TicketsType;
import com.park.common.CommonResult;
import com.park.service.ITicketsTypeService;
import com.park.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
public class TicketsTypeController {
    @Autowired
    ITicketsTypeService ticketsTypeService;

    @GetMapping("ttype")
    public CommonResult getTickets(TicketsType ticketsType, Page page){
        List<TicketsType> res=ticketsTypeService.getTicketsType(ticketsType,page);
        int count=ticketsTypeService.getCount(ticketsType);
        HashMap map=new HashMap();
        map.put("res",res);
        map.put("count",count);
        return CommonResult.success(map);
    }

    //添加数据
    @PostMapping("ttype")
    public CommonResult postTickets(@RequestBody TicketsType ticketsType){
        int count=ticketsTypeService.postTicketsType(ticketsType);
        if(count>0){
            return CommonResult.success(ticketsType);
        }else{
            return CommonResult.fail();
        }
    }

    @DeleteMapping("ttype/{id}")
    public CommonResult delTickets(@PathVariable int id){
        int count= ticketsTypeService.delTicketsType(id);
        if(count>0){
            return CommonResult.success();
        }else{
            return CommonResult.fail();
        }
    }

    @PutMapping("ttype")
    public CommonResult editTickets(@RequestBody TicketsType ticketsType){
        int count=ticketsTypeService.editTicketsType(ticketsType);
        if(count>0){
            return CommonResult.success(ticketsType);
        }else{
            return CommonResult.fail();
        }
    }

}
